<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{ Number(typeline) == 3 ? '通知' : '问卷' }}有效时间</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="120px" ref="editForm" v-if="Number(typeline)!==3">
          <el-form-item label="问卷开始时间:">
            <el-col :span="11">
              <el-date-picker type="date"
                              placeholder="开始时间"
                              v-model="infoForm.start_time"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="问卷结束时间:">
            <el-col :span="11">
              <el-date-picker type="date"
                              placeholder="结束时间"
                              v-model="infoForm.end_time"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"></el-date-picker>
            </el-col>
          </el-form-item>
        </el-form>
        <el-form label-width="120px" ref="editForm" v-if="Number(typeline)===3">
          <el-form-item label="送达时间:">
            <el-col :span="11">
              <el-date-picker type="date"
                              placeholder="送达时间"
                              v-model="time"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"></el-date-picker>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定修改</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {questionnaireEditTime} from "@/api/admin/question"
import {questionnaireInsideEditTime} from "@/api/admin/questionTeach"
import {noticeEditTime} from "@/api/admin/notice"

export default {
  props: ['visible', 'questionData', 'typeline'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      infoForm: {
        start_time: '',
        end_time: '',
      },
      time: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (Number(this.typeline) !== 3) {
          this.infoForm.start_time = this.questionData.start_time
          this.infoForm.end_time = this.questionData.end_time
        } else {
          this.time = this.questionData.time
        }
      }
    }
  },
  created() {

  },
  methods: {
    checkEditFn() {
      // typeline 1 调查问卷 2 内部问卷 3 通知问卷
      if (Number(this.typeline) === 1) {
        questionnaireEditTime({
          start_time: this.infoForm.start_time + ' 00:00:00',
          end_time: this.infoForm.end_time + ' 23:59:59',
          id: this.questionData.id
        }).then(res => {
          if (!res.code) {
            this.$message.success('操作成功！')
            this.$emit('InitFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else if (Number(this.typeline) === 2) {
        questionnaireInsideEditTime({
          start_time: this.infoForm.start_time + ' 00:00:00',
          end_time: this.infoForm.end_time + ' 23:59:59',
          id: this.questionData.id
        }).then(res => {
          if (!res.code) {
            this.$message.success('操作成功！')
            this.$emit('InitFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else if (Number(this.typeline) === 3) {
        noticeEditTime({
          time: this.time,
          id: this.questionData.id
        }).then(res => {
          if (!res.code) {
            this.$message.success('操作成功！')
            this.$emit('InitFn')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 500px;
  height: 300px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


